import request from './request'

/**
 * 项目管理API
 */

// 获取项目列表
export function getProjects(params) {
  return request({
    url: '/projects/',
    method: 'get',
    params
  })
}

// 获取项目详情
export function getProject(id) {
  return request({
    url: `/projects/${id}`,
    method: 'get'
  })
}

// 创建项目
export function createProject(data) {
  return request({
    url: '/projects/',
    method: 'post',
    data
  })
}

// 更新项目
export function updateProject(id, data) {
  return request({
    url: `/projects/${id}`,
    method: 'put',
    data
  })
}

// 删除项目
export function deleteProject(id) {
  return request({
    url: `/projects/${id}`,
    method: 'delete'
  })
}

// 上传OpenAPI文档
export function uploadOpenAPI(projectId, file) {
  const formData = new FormData()
  formData.append('file', file)
  
  return request({
    url: `/projects/${projectId}/upload-openapi`,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 解析OpenAPI文档
export function parseOpenAPI(projectId, data) {
  return request({
    url: `/projects/${projectId}/parse-openapi`,
    method: 'post',
    data
  })
}
